# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=('texinfo' 'info' 'texinfo-tex')
pkgver=6.6
pkgrel=1
pkgdesc="Utilities to work with and produce manuals, ASCII text, and on-line documentation from a single source file"
arch=('i686' 'x86_64')
url="https://www.gnu.org/software/texinfo/"
license=('GPL3')
makedepends=('libcrypt-devel' 'ncurses-devel' 'gettext-devel' 'findutils' 'gzip' 'perl')
source=(https://ftp.gnu.org/pub/gnu/${pkgname}/${pkgname}-${pkgver}.tar.xz{,.sig}
        0000-documentencoding-is-not-file-specific.patch
        0001-texinfo-6.6-msys2.patch
        0002-manifest.all.patch
        0004-no-w32-stuff.msys2.patch
        0005-fix-makeinfo-exeext.msys2.patch)
sha256sums=('9bb9ca00da53f26a7e5725eee49689cd4a1e18d25d5b061ac8b2053018d93d66'
            'SKIP'
            'd16bd1fe877ccf9f96827ff4811afcd986f575d86fd839adf62a67d64555ffc0'
            '28f148f9e5af453f87bfd026b81413a4f3b00a3bc60eaaadf5d668c22bbe152e'
            'db2c67546da5f11dc8e374dbf70269227a0df15045dc3456f7a9e74c353083d5'
            'ccf696f2777ebd2c85c4cb311a4735957ffa40952ecbe50c7031b9f05dc6cdee'
            'e5b18f11d9a5d99f96f9228266e6204cfb2e076e2d9c336db0eceb72e2252873')

prepare() {
  cd ${srcdir}/${pkgname}-${pkgver}
  patch -p1 -i ${srcdir}/0000-documentencoding-is-not-file-specific.patch
  patch -p1 -i ${srcdir}/0001-texinfo-6.6-msys2.patch
  patch -p1 -i ${srcdir}/0002-manifest.all.patch
  patch -p1 -i ${srcdir}/0004-no-w32-stuff.msys2.patch
  patch -p1 -i ${srcdir}/0005-fix-makeinfo-exeext.msys2.patch

  autoreconf -fiv
  pushd tp/Texinfo/XS
    autoreconf -fiv
  popd
}

build() {
  cd ${srcdir}/${pkgname}-${pkgver}
  ./configure \
    --build=${CHOST} \
    --prefix=/usr \
    --without-libiconv-prefix \
    --without-libintl-prefix \
    --enable-perl-xs

  make
  make DESTDIR=${srcdir}/dest install
}

check() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make check
}

package_texinfo() {
  depends=('info' 'perl' 'sh')
  groups=('base-devel')
  install=texinfo.install

  mkdir -p ${pkgdir}/usr/{bin,lib}
  mkdir -p ${pkgdir}/usr/share/info
  mkdir -p ${pkgdir}/usr/share/man/man{1,5}
  for ff in makeinfo pod2texi texi2any; do
    cp -f ${srcdir}/dest/usr/bin/${ff} ${pkgdir}/usr/bin/${ff}
    cp -f ${srcdir}/dest/usr/share/man/man1/${ff}.1 ${pkgdir}/usr/share/man/man1/${ff}.1
  done
  cp -rf ${srcdir}/dest/usr/lib/texinfo ${pkgdir}/usr/lib/
  cp -rf ${srcdir}/dest/usr/share/locale ${pkgdir}/usr/share/
  cp -rf ${srcdir}/dest/usr/share/texinfo ${pkgdir}/usr/share/
  cp -f ${srcdir}/dest/usr/share/man/man5/texinfo.5 ${pkgdir}/usr/share/man/man5/
  cp -f ${srcdir}/dest/usr/share/info/texinfo.info{,-1,-2,-3} ${pkgdir}/usr/share/info/
}

package_info() {
  depends=('gzip' 'libcrypt' 'libintl' 'ncurses')
  groups=(base)
  install=info.install

  mkdir -p ${pkgdir}/usr/{bin,share}
  mkdir -p ${pkgdir}/usr/share/info
  mkdir -p ${pkgdir}/usr/share/man/man{1,5}
  for ff in info install-info; do
    cp -f ${srcdir}/dest/usr/bin/${ff}.exe ${pkgdir}/usr/bin/${ff}.exe
    cp -f ${srcdir}/dest/usr/share/man/man1/${ff}.1 ${pkgdir}/usr/share/man/man1/${ff}.1
  done
  cp -f ${srcdir}/dest/usr/share/man/man5/info.5 ${pkgdir}/usr/share/man/man5/info.5
  cp -f ${srcdir}/dest/usr/share/info/info-stnd.info ${pkgdir}/usr/share/info/info-stnd.info
}

package_texinfo-tex() {
  depends=('gawk' 'perl' 'sh')
  groups=('base-devel')

  mkdir -p ${pkgdir}/usr/{bin,share}
  mkdir -p ${pkgdir}/usr/share/man/man1
  for ff in texindex texi2dvi texi2pdf pdftexi2dvi; do
    cp -f ${srcdir}/dest/usr/bin/${ff} ${pkgdir}/usr/bin/${ff}
    cp -f ${srcdir}/dest/usr/share/man/man1/${ff%.*}.1 ${pkgdir}/usr/share/man/man1/${ff%.*}.1
  done
}
